/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
export default function access(initialState: { currentUser?: API.CurrentUser } | undefined) {
    const {currentUser} = initialState ?? {};
    const authoritySystemAdmin = '1'
    const authoritySystemUser = '2'
    const authoritySystemOrderAdmin = '3'
    const authorityCustomAdmin = '10'
    const authorityCustomUser = '11'
    const systemResourceIds = [authoritySystemAdmin, authoritySystemUser]

    // dashboard一级菜单
    const hasDashboardParentIds = [authoritySystemAdmin, authoritySystemUser]
    // dashboard 统计页
    const hasDashboardStatisticsIds = [authoritySystemAdmin, authoritySystemUser]

    // 组织管理一级菜单
    const hasOrganizationParentIds = [authoritySystemAdmin, authoritySystemUser, authorityCustomAdmin]

    // 组织管理 组织列表页
    const hasOrganizationOrgIds = [authoritySystemAdmin, authoritySystemUser]

    // 组织管理 用户列表页
    const hasOrganizationUserIds = [authoritySystemAdmin, authoritySystemUser, authorityCustomAdmin]

    // 算力中心一级菜单
    const hasPowerParentIds = [authoritySystemAdmin, authoritySystemUser, authorityCustomAdmin, authorityCustomUser]

    // 算力中心系统侧资源管理
    const hasPowerSystemResourceManagerIds = [authoritySystemAdmin, authoritySystemUser]

    // 算力中心租户侧资源管理
    const hasPowerCustomResourceManagerIds = [authorityCustomAdmin, authorityCustomUser]

    // 结算中心一级菜单
    const hasOrderParentIds = [authoritySystemAdmin, authoritySystemOrderAdmin]

    // 系统设置一级菜单
    const hasSystemConfigParentIds = [authoritySystemAdmin]

    // License一级菜单
    const hasLicenseParentIds = [authoritySystemAdmin]

    return {
        isSystem: currentUser && currentUser.authority?.authorityType === 'system',
        isCustom: currentUser && currentUser.authority?.authorityType !== 'system',

        isSystemResource: currentUser && systemResourceIds.includes(currentUser.authority?.authorityId),

        // 系统财务角色，只有账单管理权限
        isSystemOrder: currentUser && currentUser.authority?.authorityType === 'system' &&
            (currentUser.authority?.authorityId === '1' || currentUser.authority?.authorityId === '3'),

        isSystemAdmin: currentUser && (currentUser.authority?.authorityId === '1'),

        // 系统管理员 & 租户管理员
        isAdmin: currentUser && (currentUser.authority?.authorityId === '1' || currentUser.authority?.authorityId === '10'),

        // 租户管理员
        isCustomAdmin: currentUser && (currentUser.authority?.authorityId === '10'),

        // dashboard一级菜单
        hasDashboard: currentUser && hasDashboardParentIds.includes(currentUser.authority?.authorityId),

        // 组织管理一级菜单
        hasOrganization: currentUser && hasOrganizationParentIds.includes(currentUser.authority?.authorityId),

        // 组织列表
        hasOrganizationOrg: currentUser && hasOrganizationOrgIds.includes(currentUser.authority?.authorityId),
        // 用户列表
        hasOrganizationUser: currentUser && hasOrganizationUserIds.includes(currentUser.authority?.authorityId),

        // 算力中心一级菜单
        hasPower: currentUser && hasPowerParentIds.includes(currentUser.authority?.authorityId),

        // 算力中心系统侧资源菜单
        hasPowerSystemResourceManager: currentUser && hasPowerSystemResourceManagerIds.includes(currentUser.authority?.authorityId),

        // 算力中心租户侧资源菜单
        hasPowerCustomResourceManager: currentUser && hasPowerCustomResourceManagerIds.includes(currentUser.authority?.authorityId),

        // 结算中心一级菜单
        hasOrder: currentUser && hasOrderParentIds.includes(currentUser.authority?.authorityId),

        // 系统设置一级菜单
        hasSystemConfig: currentUser && hasSystemConfigParentIds.includes(currentUser.authority?.authorityId),

        // License一级菜单
        hasLicense: currentUser && hasLicenseParentIds.includes(currentUser.authority?.authorityId),
    };
}
